<?php
	include_once('mysql_connection.php');
	$type = $_GET['type'];
	$article_id = $_GET['article_id'];
	$user_ip = $_GET['ip'];
	$return_count = 0;
	
	$query_ip = "select * from `toupiao_ip` where `article_id`=".$article_id." and `ip`='".$user_ip."'";
	$result_ip = @$mysql_connection->query($query_ip);
	if (@$result_ip->num_rows >= 1) {
		$return_count = -1;
	} else {
		// start 如果点击的是支持，更新数据库，并且查询当前数据
		if ($type == 'zhichi') {
			$query = "update `articles` set `zhichi`=`zhichi`+1 where `id`=".$article_id;
			$result_query = $mysql_connection->query($query);

			$query = "select `zhichi` from `articles` where `id`=".$article_id;
			$result_query = $mysql_connection->query($query);
			$return_count = $result_query->fetch_assoc();
			$return_count = $return_count['zhichi'];
		} else if ($type == 'fandui') {
			$query = "update `articles` set `fandui`=`fandui`+1 where `id`=".$article_id;
			$result_query = $mysql_connection->query($query);

			$query = "select `fandui` from `articles` where `id`=".$article_id;
			$result_query = $mysql_connection->query($query);
			$return_count = $result_query->fetch_assoc();
			$return_count = $return_count['fandui'];
		}
		$query_t = "insert into `toupiao_ip` (`article_id`,`ip`) values(".$article_id.",'".$user_ip."')";
		$mysql_connection->query($query_t);
	}
	echo $return_count;
?>
